#include "siteinfo.h"
#include "ui_siteinfo.h"

#include <qdatetime.h>
#include <logwindow.h>

siteInfo::siteInfo(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::siteInfo)
{
    ui->setupUi(this);
}

siteInfo::~siteInfo()
{
    delete ui;
}

void siteInfo::leaveEvent(QEvent *)
{
    this->hide();
}

void siteInfo::leaveClick()
{
    this->hide();
}

void siteInfo::setInfo(QString siteName, QString DotName, int errorCategory,QString time)
{
    if(getDotName == DotName)
    {
        getDotName1 = DotName;
        errorCategory1 = errorCategory;
        siteName1 = siteName;
        //更改信息
        ui->widget_error->show();
        ui->widget_common->hide();
        ui->widget_3->show();
        ui->pushButton->show();
        ui->dotName->setText(DotName);
        ui->sitName->setText(siteName);
        switch (errorCategory) {
        case 0 :
            ui->wanning->setText("一级警报");
            break;
        case 1 :
            ui->wanning->setText("二级警报");
            break;
        case 2 :
            ui->wanning->setText("三级警报");
            break;

        }
        //更改时间
        ui->wanningTime->setText(time);

        //二级平面图的更换
        QImage *img=new QImage;
        //判断该区域的图片
        if(DotName.contains("原料厂",Qt::CaseSensitive))
        {
            img->load(":/res/pic/1.jpg");
        }
        else if(DotName.contains("研究所",Qt::CaseSensitive))
        {
            img->load(":/res/pic/2.jpg");
        }
        else if(DotName.contains("陶瓷基地",Qt::CaseSensitive))
        {
            img->load(":/res/pic/3.jpg");
        }
        else if(DotName.contains("建材基地",Qt::CaseSensitive))
        {
            img->load(":/res/pic/4.jpg");
        }
        else if(DotName.contains("大楼",Qt::CaseSensitive))
        {
            img->load(":/res/pic/5.jpg");
        }
        else if(DotName.contains("车间1",Qt::CaseSensitive))
        {
            img->load(":/res/pic/6.jpg");
        }
        else if(DotName.contains("车间2",Qt::CaseSensitive))
        {
            img->load(":/res/pic/7.jpg");
        }
        else if(DotName.contains("车间3",Qt::CaseSensitive))
        {
            img->load(":/res/pic/8.jpg");
        }
        else if(DotName.contains("职工宿舍",Qt::CaseSensitive))
        {
            img->load(":/res/pic/9.jpg");
        }
        else
        {
            return;
        }
        ui->label->setPixmap(QPixmap::fromImage(*img));  //设置图片
        ui->label->resize(QSize(img->width(),img->height()));  //设置图片适应label框
    }
}

void siteInfo::setInfoCommon(QString DotName)
{
    if(getDotName == DotName)
    {
        //隐藏和显示
        ui->widget_common->show();
        ui->widget_error->hide();
        ui->pushButton->hide();
        getDotName1 = DotName;
        //更改信息
        ui->dotNameCommon->setText(DotName);  //区域名
       //区域位置
        QList<QList<QString> > Region = DB.showRegion();
        for(int i=0 ; i<Region.size();i++)
        {
          if(Region[i].at(0)==DotName)
          {
              ui->position->setText(Region[i].at(1));  //位置
          }
        }
        //站点数量
        QList<QList<QString> > Site = DB.showSite();
        int siteNumber=0;
        for(int i=0 ; i<Site.size();i++)
        {
          if(Site[i].at(1)==DotName)
          {
              siteNumber++;
          }
        }
        ui->siteNumber->setText(QString::number(siteNumber));  //站点数


        //二级平面图的更换
        QImage *img=new QImage;
        //判断该区域的图片
        if(DotName.contains("原料厂",Qt::CaseSensitive))
        {
            img->load(":/res/pic/1.jpg");
        }
        else if(DotName.contains("研究所",Qt::CaseSensitive))
        {
            img->load(":/res/pic/2.jpg");
        }
        else if(DotName.contains("陶瓷基地",Qt::CaseSensitive))
        {
            img->load(":/res/pic/3.jpg");
        }
        else if(DotName.contains("建材基地",Qt::CaseSensitive))
        {
            img->load(":/res/pic/4.jpg");
        }
        else if(DotName.contains("大楼",Qt::CaseSensitive))
        {
            img->load(":/res/pic/5.jpg");
        }
        else if(DotName.contains("车间1",Qt::CaseSensitive))
        {
            img->load(":/res/pic/6.jpg");
        }
        else if(DotName.contains("车间2",Qt::CaseSensitive))
        {
            img->load(":/res/pic/7.jpg");
        }
        else if(DotName.contains("车间3",Qt::CaseSensitive))
        {
            img->load(":/res/pic/8.jpg");
        }
        else if(DotName.contains("职工宿舍",Qt::CaseSensitive))
        {
            img->load(":/res/pic/9.jpg");
        }
        else
        {
            return;
        }
        ui->label->setPixmap(QPixmap::fromImage(*img));  //设置图片
        ui->label->resize(QSize(img->width(),img->height()));  //设置图片适应label框


    }
}

bool siteInfo::theSame(QString dotName)
{
    getDotName =dotName;
}
//点击解除按钮
void siteInfo::on_pushButton_clicked()
{
//    connect()
    emit relieve( getDotName1,errorCategory1,siteName1);

}

//点击查看历史
void siteInfo::on_lookHistory_clicked()
{
    LogWindow *log=new LogWindow;
    log->show();
}
